//
//  CXHUnStandardViewController.m
//  CXHAdSDK_Example
//
//  Created by 陈坤 on 2022/5/30.
//  Copyright © 2022 陈桑葚吃桑葚. All rights reserved.
//

#import "CXHUnStandardViewController.h"
#import <CXHAdSDK-Core/CXHAdSDK.h>
#import <CXHAdSDK-Core/CXHAdSDKServiceAdView.h>
#import <CXHAdSDK-Kit/CXHUtilsKit.h>
#import <CXHAdSDK-Adapter/CXHAdSDKAdapter.h>

@interface CXHUnStandardViewController ()<CXHSDKServiceAdViewDelegate>{
    CXHAdSDKServiceAdView *_serviceView;
}

@end

@implementation CXHUnStandardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    UIBarButtonItem *itemLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancelClicked:)];
    self.navigationItem.leftBarButtonItem = itemLeft;
    
    UIButton *btn2 = [UIButton new];
    btn2.backgroundColor = [UIColor orangeColor];
    btn2.layer.cornerRadius = 20;
    
    btn2.frame = CGRectMake((kCXHScreenWidth -200)/2, kCXHTopBarHeight + 100, 200, 40);
    [btn2 setTitle:@"load unstandarAd" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [btn2 addTarget:self action:@selector(loadservice) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)onCancelClicked:(id)sender {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)loadservice {
    
    _serviceView = [[CXHAdSDKServiceAdView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    
    _serviceView.delegate = self;
    _serviceView.controller = self;
    _serviceView.posId = @"54231494";
    _serviceView.backgroundColor = [UIColor whiteColor];
    
    // 2 添加到父视图上
    _serviceView.frame = CGRectMake(200, 400, 50, 50);
    [self.view addSubview:_serviceView];
    [_serviceView loadAndShow];
    
}

#pragma mark - CXHSDKServiceAdViewDelegate
/**
 广告获取成功
 
 @param serviceAdView banner实例
 */
- (void)CXH_serviceAdViewDidReceived:(CXHAdSDKServiceAdView *)serviceAdView{
    
}

/**
 广告拉取失败
 
 @param serviceAdView banner实例
 @param error 错误描述
 */
- (void)CXH_serviceAdViewFailToReceived:(CXHAdSDKServiceAdView *)serviceAdView error:(NSError *)error{
    NSLog(@"=====fail=====%@", error);
}

/**
 广告点击
 
 @param serviceAdView 广告实例
 @param loadingPageURL 广告落地页地址，当渠道为bwt，并且customLoadingPage为YES时有值
 */
- (void)CXH_serviceAdViewClicked:(CXHAdSDKServiceAdView *)serviceAdView loadingPageURL:(NSString *)loadingPageURL{
    
}

/**
 广告关闭
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewClose:(CXHAdSDKServiceAdView *)serviceAdView{
    
}

/**
 广告展示
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewExposure:(CXHAdSDKServiceAdView *)serviceAdView{
    
}

/**
 关闭落地页
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewCloseLandingPage:(CXHAdSDKServiceAdView *)serviceAdView{
    
}

- (void)CXH_serviceAdViewClickedReport:(nonnull CXHAdSDKServiceAdView *)serviceAdView { 
    
}


- (void)CXH_serviceAdViewExposureReport:(nonnull CXHAdSDKServiceAdView *)serviceAdView { 
    
}

@end
